﻿Imports System.Windows.Forms
Imports System.Drawing
Imports Logica

Public Class frmInicio


    Private Sub frmIncio_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        If MessageBox.Show("¿Esta seguro que desea salir?", "Salir", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
            e.Cancel = True
            'si no sale, le dejo el boton salir sin fondo y con el color de bloqueo
            btnSalir.BackColor = Color.Transparent
            btnSalir.BackgroundImage = My.Resources.btnMenuBloqueado

        End If

    End Sub

   
    Private Sub btnSalir_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnSalir.MouseClick

        If AccesoLogica.getUsuarioActivo Is Nothing Then
            btnLoginInicio.BackgroundImage = My.Resources.btnMenuBloqueado
            btnCierres.BackgroundImage = My.Resources.btnMenuBloqueado
            btnInformes.BackgroundImage = My.Resources.btnMenuBloqueado
            btnNC.BackgroundImage = My.Resources.btnMenuBloqueado
            btnIntegracion.BackgroundImage = My.Resources.btnMenuBloqueado
            btnSalir.BackgroundImage = My.Resources.btnMenuA1 'cambio color de boton salir

            Windows.Forms.Application.Exit()
        Else
            MessageBox.Show("Hay cajeros pendientes sin cierre, debe cerrarlos para poder salir", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If

    End Sub



    Public Sub frmInicio_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        btnLoginInicio.Enabled = False
        btnNC.Enabled = False
        btnInformes.Enabled = False
        btnIntegracion.Enabled = False
        cargarLogin()

    End Sub


    Private Sub btnLoginInicio_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnLoginInicio.MouseClick

        If AccesoLogica.getUsuarioActivo Is Nothing Then
            If btnCierres.Enabled Then
                cargarLogin()
            Else
                btnCierres.Enabled = True
                cargarLogin()
            End If
        Else
            btnNC.Enabled = True
            cargarFacturacion()
        End If

    End Sub

    Public Sub cargarLogin()

        vaciarPanel()

        'se reemplazo para que cargue las imagenes
        btnLoginInicio.BackgroundImage = My.Resources.btnMenuInicioS
        btnCierres.BackgroundImage = My.Resources.btnMenuBloqueado
        btnInformes.BackgroundImage = My.Resources.btnMenuBloqueado
        btnNC.BackgroundImage = My.Resources.btnMenuBloqueado
        btnIntegracion.BackgroundImage = My.Resources.btnMenuIntegrarOff
        btnSalir.BackgroundImage = My.Resources.btnMenuBloqueado

        Dim fh As frmLogin = New frmLogin

        fh.TopLevel = False
        fh.FormBorderStyle = FormBorderStyle.None
        fh.Dock = DockStyle.Fill
        'Me.panelInicio.Controls.Add(fh)
        SplitContainer1.Panel2.Controls.Add(fh)
        fh.agregar(Me)
        fh.Show()

    End Sub

    Public Sub cargarFacturacion()

        vaciarPanel()
        btnLoginInicio.Enabled = False

        Dim ff As frmFacturacion = New frmFacturacion

        ff.TopLevel = False
        ff.FormBorderStyle = FormBorderStyle.None
        ff.Dock = DockStyle.Fill
        SplitContainer1.Panel2.Controls.Add(ff)

        ff.Show()

    End Sub

    Private Sub btnNC_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnNC.MouseClick

        If btnCierres.Enabled Then
            cargarNC()
        Else
            btnCierres.Enabled = True
            btnLoginInicio.Enabled = True
            btnNC.Enabled = False
            cargarNC()
        End If

    End Sub

    Public Sub cargarNC()

        vaciarPanel()

        btnNC.Enabled = False
        btnLoginInicio.Enabled = True

        Dim nc As frmNotasdeCredito = New frmNotasdeCredito

        nc.TopLevel = False
        nc.FormBorderStyle = FormBorderStyle.None
        nc.Dock = DockStyle.Fill
        'Me.panelInicio.Controls.Add(fh)
        SplitContainer1.Panel2.Controls.Add(nc)
        nc.agregar(Me)
        nc.Show()

    End Sub

  

    Private Sub btnCierres_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnCierres.MouseClick

        If AccesoLogica.getUsuarioActivo() Is Nothing Then
            cargarCierre()
        Else
            If MessageBox.Show("¿Cerrar el turno del cajero " & AccesoLogica.getUsuarioActivo() & "?.", "Cerrar turno", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
                btnLoginInicio.Text = "Iniciar sesión"
                cargarCierre()
                btnLoginInicio.Enabled = False
            End If
        End If

    End Sub

    Public Sub cargarCierre()

        vaciarPanel()

        btnCierres.BackgroundImage = My.Resources.btnMenuA1

        'Deshabilito el boton cierres
        btnCierres.Enabled = False
        btnLoginInicio.Enabled = True

        btnLoginInicio.BackgroundImage = My.Resources.btnMenuBloqueado
        btnInformes.BackgroundImage = My.Resources.btnMenuBloqueado
        btnNC.BackgroundImage = My.Resources.btnMenuBloqueado
        btnIntegracion.BackgroundImage = My.Resources.btnMenuBloqueado
        btnSalir.BackgroundImage = My.Resources.btnMenuBloqueado

        Dim cierre As frmCierres = New frmCierres

        cierre.TopLevel = False
        cierre.FormBorderStyle = FormBorderStyle.None
        cierre.Dock = DockStyle.Fill
        'Me.panelInicio.Controls.Add(fh)
        SplitContainer1.Panel2.Controls.Add(cierre)
        cierre.agregar(Me)
        cierre.Show()

    End Sub


    Public Sub vaciarPanel()


        If SplitContainer1.Panel2.Controls.Count > 0 Then

            SplitContainer1.Panel2.Controls.RemoveAt(0)

        End If

    End Sub


    Private Sub btnIntegracion_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnIntegracion.MouseClick

        vaciarPanel()

        Dim fh As frmintegrador = New frmintegrador

        fh.TopLevel = False
        fh.FormBorderStyle = FormBorderStyle.None
        fh.Dock = DockStyle.Fill
        'Me.panelInicio.Controls.Add(fh)
        SplitContainer1.Panel2.Controls.Add(fh)
        fh.agregar(Me)
        fh.Show()

    End Sub


    
End Class